home *** CD-ROM | disk | FTP | other *** search
/ 17 Bit Software 6: Level 6 / 17 Bit - Level 6 (1998)(Epic Marketing)[!].iso / quartz / q0429.dms / q0429.adf / libray / libcommon / vector.h < prev    next >
C/C++ Source or Header  |  1992-05-20  |  2KB  |  90 lines

  1. /*
  2.  * vector.h
  3.  *
  4.  * Copyright (C) 1989, 1991, Craig E. Kolb
  5.  * All rights reserved.
  6.  *
  7.  * This software may be freely copied, modified, and redistributed
  8.  * provided that this copyright notice is preserved on all copies.
  9.  *
  10.  * You may not distribute this software, in whole or in part, as part of
  11.  * any commercial product without the express consent of the authors.
  12.  *
  13.  * There is no warranty or other guarantee of fitness of this software
  14.  * for any purpose.  It is provided solely "as is".
  15.  *
  16.  * $Id: vector.h,v 4.0.1.1 91/11/26 21:34:41 cek Exp Locker: cek $
  17.  *
  18.  * $Log:    vector.h,v $
  19.  * Revision 4.0.1.1  91/11/26  21:34:41  cek
  20.  * patch3: Moved EPSILON definition.
  21.  * 
  22.  * Revision 4.0  91/07/17  14:33:11  kolb
  23.  * Initial version.
  24.  * 
  25.  */
  26. #ifndef VECTOR_H
  27. #define VECTOR_H
  28. /*
  29.  * Constants used in projecting onto planes
  30.  */
  31. #define XNORMAL        (char)0
  32. #define YNORMAL        (char)1
  33. #define ZNORMAL        (char)2
  34.  
  35. /*
  36.  * Maximum length
  37.  */
  38. #define FAR_AWAY        1.0E+14
  39.  
  40. typedef struct {
  41.     Float u, v;            /* 2D point */
  42. } Vec2d;
  43.  
  44. typedef struct Vector {
  45.     Float x, y, z;            /* 3D point */
  46. } Vector;
  47.  
  48. /*
  49.  * Linked list of points
  50.  */
  51. typedef struct PointList {
  52.     Vector    vec;            /* Vector data */
  53.     struct    PointList *next;    /* Next in list */
  54. } PointList;
  55.  
  56. /*
  57.  * Project a point in 3-space to the plane whose normal is indicated by "i."
  58.  */
  59. #define VecProject(r, p, i)    {switch(i) { \
  60.                 case XNORMAL: \
  61.                     r.u = (p).y; \
  62.                     r.v = (p).z; \
  63.                     break; \
  64.                 case YNORMAL: \
  65.                     r.u = (p).x; \
  66.                     r.v = (p).z; \
  67.                     break; \
  68.                 case ZNORMAL: \
  69.                     r.u = (p).x; \
  70.                     r.v = (p).y; \
  71.                     break; \
  72.                   } }
  73.  
  74. #define dotp(a, b)    (((a)->x*(b)->x)+((a)->y*(b)->y)+((a)->z*(b)->z))
  75. #define VecSub(a,b,r) (r)->x=(a).x-(b).x,(r)->y=(a).y-(b).y,(r)->z=(a).z-(b).z
  76. #define VecAdd(a,b,r) (r)->x=(a).x+(b).x,(r)->y=(a).y+(b).y,(r)->z=(a).z+(b).z
  77. #define VecScale(s,a,r)  (r)->x=(s)*(a).x,(r)->y=(s)*(a).y,(r)->z=(s)*(a).z
  78. #define VecComb(s1,v1,s2,v2,r)    (r)->x = (s1)*(v1).x + (s2)*(v2).x, \
  79.                  (r)->y = (s1)*(v1).y + (s2)*(v2).y, \
  80.                  (r)->z = (s1)*(v1).z + (s2)*(v2).z
  81. #define VecAddScaled(v1,s,v2,r)    (r)->x = (v1).x + (s)*(v2).x, \
  82.                  (r)->y = (v1).y + (s)*(v2).y, \
  83.                  (r)->z = (v1).z + (s)*(v2).z
  84.  
  85. extern void    VecCross(), VecCoordSys(), MakeBump();
  86. extern Float    VecNormCross(), VecNormalize();
  87. extern int    Refract();
  88.  
  89. #endif /* VECTOR_H */
  90.